This is known to crash right now, and that will anger Jenkins, but this will only hurt for a
little while. (I hope.) The changes are too good to leave unmerged - let's tackle them
together.
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
#if HAVE_LIBEXPAT
# define XML_UNICODE
#endif
+#define CSTR(qstr) (qstr.toUtf8().constData())
+#define CSTRE_(qstr, enc) (enc->fromUnicode(qstr).constData())
+#define CSTRE(qstr) (CSTRE_(qstr, codec))
+
/*
* Amazingly, this constant is not specified in the standard...
*/
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "jeeps/gpsmath.h"
#include "xmlgeneric.h"
#if !ZLIB_INHIBITED
static void
-tlog3a_xgcb_version(const char* args, const char** unused)
+tlog3a_xgcb_version(const char* args, const QXmlStreamAttributes* unused)
{
if (strcmp(args, "1") != 0) {
fatal(MYNAME ": Unsupported file version '%s'!\n", args);
}
static void
-tlog3a_xgcb_length(const char* args, const char** unused)
+tlog3a_xgcb_length(const char* args, const QXmlStreamAttributes* unused)
{
}
static void
-tlog3a_xgcb_data(const char* args, const char** unused)
+tlog3a_xgcb_data(const char* args, const QXmlStreamAttributes* unused)
{
int len;
char* bin;
static void
-tlog3b_xgcb_tfna(const char* args, const char** unused)
+tlog3b_xgcb_tfna(const char* args, const QXmlStreamAttributes* unused)
{
if (xmltrk == NULL) {
xmltrk = route_head_alloc();
static void
-tlog3b_xgcb_tfdes(const char* args, const char** unused)
+tlog3b_xgcb_tfdes(const char* args, const QXmlStreamAttributes* unused)
{
if (xmltrk == NULL) {
xmltrk = route_head_alloc();
static void
-tlog3b_xgcb_wptst(const char* args, const char** unused)
+tlog3b_xgcb_wptst(const char* args, const QXmlStreamAttributes* unused)
{
xmlwpt = waypt_new();
xmldatum = DATUM_WGS84;
static void
-tlog3b_xgcb_tptst(const char* args, const char** unused)
+tlog3b_xgcb_tptst(const char* args, const QXmlStreamAttributes* unused)
{
xmlwpt = waypt_new();
xmldatum = DATUM_WGS84;
static void
-tlog3b_xgcb_tpten(const char* args, const char** unused)
+tlog3b_xgcb_tpten(const char* args, const QXmlStreamAttributes* unused)
{
finalize_pt(xmlwpt);
static void
-tlog3b_xgcb_wptid(const char* args, const char** unused)
+tlog3b_xgcb_wptid(const char* args, const QXmlStreamAttributes* unused)
{
if (*args) {
xmlwpt->shortname = xstrdup(args);
static void
-tlog3b_xgcb_wptdt(const char* args, const char** unused)
+tlog3b_xgcb_wptdt(const char* args, const QXmlStreamAttributes* unused)
{
xmldatum = GPS_Lookup_Datum_Index(args);
}
static void
-tlog3b_xgcb_wptgr(const char* args, const char** unused)
+tlog3b_xgcb_wptgr(const char* args, const QXmlStreamAttributes* unused)
{
if (xmlgrid != NULL) {
if (strcmp(xmlgrid, args) == 0) {
static void
-tlog3b_xgcb_wptno(const char* args, const char** unused)
+tlog3b_xgcb_wptno(const char* args, const QXmlStreamAttributes* unused)
{
xmlNorthing = atof(args);
}
static void
-tlog3b_xgcb_wptea(const char* args, const char** unused)
+tlog3b_xgcb_wptea(const char* args, const QXmlStreamAttributes* unused)
{
xmlEasting = atof(args);
}
static void
-tlog3b_xgcb_wptal(const char* args, const char** unused)
+tlog3b_xgcb_wptal(const char* args, const QXmlStreamAttributes* unused)
{
xmlAltitude = atof(args);
}
static void
-tlog3b_xgcb_tptdt(const char* args, const char** unused)
+tlog3b_xgcb_tptdt(const char* args, const QXmlStreamAttributes* unused)
{
xmldatum = GPS_Lookup_Datum_Index(args);
}
static void
-tlog3b_xgcb_wpten(const char* args, const char** unused)
+tlog3b_xgcb_wpten(const char* args, const QXmlStreamAttributes* unused)
{
finalize_pt(xmlwpt);
waypt_add(xmlwpt);
// http://developer.garmin.com/web-device/garmin-mass-storage-mode-devices/
// http://developer.garmin.com/schemas/device/v2/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
#include "garmin_device_xml.h"
static xg_callback device_s, id_s, path_s, ext_s, base_s, dir_s;
jmp_buf gdx_jmp_buf;
-void type_s(const char* args, const char** unused)
+void type_s(const char* args, const QXmlStreamAttributes* unused)
{
type = strcmp(args, "GPSData");
}
-void device_s(const char* args, const char** unused)
+void device_s(const char* args, const QXmlStreamAttributes* unused)
{
if (my_gdx_info) {
fatal(MYNAME ": More than one device type found in file.\n");
my_gdx_info->device_desc = xstrdup(args);
}
-void id_s(const char* args, const char** unused)
+void id_s(const char* args, const QXmlStreamAttributes* unused)
{
my_gdx_info->device_id = xstrdup(args);
}
-void path_s(const char* args, const char** unused)
+void path_s(const char* args, const QXmlStreamAttributes* unused)
{
path = xstrdup(args);
}
-void ext_s(const char* args, const char** unused)
+void ext_s(const char* args, const QXmlStreamAttributes* unused)
{
ext = xstrdup(args);
}
-void base_s(const char* args, const char** unused)
+void base_s(const char* args, const QXmlStreamAttributes* unused)
{
base = xstrdup(args);
}
-void dir_s(const char* args, const char** unused)
+void dir_s(const char* args, const QXmlStreamAttributes* unused)
{
if (type) {
return;
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
gbfprintf(ofd, "</History>\n");
}
-void gl_trk_s(const char* args, const char** unused)
+void gl_trk_s(const char* args, const QXmlStreamAttributes* unused)
{
trk_head = route_head_alloc();
track_add_head(trk_head);
}
#if 0
-void gl_trk_ident(const char* args, const char** unused)
+void gl_trk_ident(const char* args, const QXmlStreamAttributes* unused)
{
trk_head->rte_name = xstrdup(args);
}
#endif
-void gl_trk_pnt_s(const char* args, const char** unused)
+void gl_trk_pnt_s(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp = waypt_new();
}
-void gl_trk_pnt_e(const char* args, const char** unused)
+void gl_trk_pnt_e(const char* args, const QXmlStreamAttributes* unused)
{
track_add_wpt(trk_head, wpt_tmp);
}
-void gl_trk_utc(const char* args, const char** unused)
+void gl_trk_utc(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->SetCreationTime(xml_parse_time(args));
}
-void gl_trk_lat(const char* args, const char** unused)
+void gl_trk_lat(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->latitude = atof(args);
}
-void gl_trk_long(const char* args, const char** unused)
+void gl_trk_long(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->longitude = atof(args);
}
-void gl_trk_alt(const char* args, const char** unused)
+void gl_trk_alt(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->altitude = atof(args);
}
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
+
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
{ NULL, (xg_cb_type)0, NULL }
};
-void goog_script(const char* args, const char** unused)
+void goog_script(const char* args, const QXmlStreamAttributes *unused)
{
if (args) {
if (script) {
}
}
-void goog_points(const char* args, const char** unused)
+void goog_points(const char* args, const QXmlStreamAttributes *unused)
{
if (args) {
if (encoded_points) {
}
}
-void goog_levels(const char* args, const char** unused)
+void goog_levels(const char* args, const QXmlStreamAttributes *unused)
{
if (args) {
if (encoded_levels) {
* The segments contain an index into the points array. We use that
* index to find the waypoint and insert a better name for it.
*/
-void goog_segment_s(const char* args, const char** attrv)
+void goog_segment_s(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
- while (*avp) {
- if (0 == strcmp(avp[0], "pointIndex")) {
- snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x", atoi(avp[1]));
- }
- avp += 2;
+ QStringRef ptidx = attrv->value("pointIndex");
+ if (!ptidx.isEmpty()) {
+ snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x",
+ ptidx.toString().toUInt());
}
-
}
-void goog_segment(const char* args, const char** unused)
+void goog_segment(const char* args, const QXmlStreamAttributes *unused)
{
waypoint* wpt_tmp;
wpt_tmp = route_find_waypt_by_name(routehead[goog_segroute], goog_segname);
if (wpt_tmp) {
xfree(wpt_tmp->shortname);
- wpt_tmp->shortname = mkshort(desc_handle,args);
+ wpt_tmp->shortname = mkshort(desc_handle, args);
wpt_tmp->description = xstrdup(args);
}
}
-void goog_td_s(const char* args, const char** attrv)
+void goog_td_s(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
- int isdesc = 0;
- int isseg = 0;
- while (*avp) {
- if (0 == strcmp(avp[0], "class")) {
- isdesc = !strcmp(avp[1], "desc");
- isseg = !strcmp(avp[1], "dirsegtext");
- } else if (isdesc && (0 == strcmp(avp[0], "id"))) {
- goog_segroute = 0;
- snprintf(goog_segname, sizeof(goog_segname),
- "\\%5.5x",
- atoi(avp[1] + 6));
- } else if (isseg && (0 == strcmp(avp[0], "id"))) {
- if (strchr(strchr(avp[1],'_')+1,'_')) {
- goog_segroute = atoi(strchr(avp[1],'_')+1);
- } else {
- goog_segroute = 0;
- }
- snprintf(goog_segname, sizeof(goog_segname),
- "\\%5.5x",
- atoi(strrchr(avp[1],'_') + 1)+routecount[goog_segroute]);
+ bool isdesc = false, isseg = false;
+ QStringRef aclass = attrv->value("class");
+ QStringRef id = attrv->value("id");
+
+ if (aclass.isEmpty() || id.isEmpty()) {
+ return;
+ }
+
+ isdesc = (aclass == "desc");
+ isseg = (aclass == "dirsegtext");
+
+ if (isdesc) {
+ QStringRef subid(id.string(), id.position() + 6, id.length() - 6);
+
+ goog_segroute = 0;
+ snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x",
+ subid.toString().toUInt());
+ } else if (isseg) {
+ QString idstr = id.toString();
+ int first_us;
+
+ goog_segroute = 0;
+
+ first_us = idstr.indexOf("_");
+ if (idstr.indexOf("_", first_us + 1) != -1) {
+ goog_segroute = idstr.mid(first_us + 1).toUInt();
}
- avp += 2;
+
+ snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x",
+ idstr.mid(idstr.lastIndexOf("_") + 1).toUInt() +
+ routecount[goog_segroute]);
}
}
-void goog_td_b(const char* args, const char** attrv)
+void goog_td_b(const char* args, const QXmlStreamAttributes* unused)
{
if (goog_segname[0] == '\\' && !strchr(args, '\xa0')) {
if (goog_realname) {
strcpy(goog_realname, args);
}
}
-void goog_td_e(const char* args, const char** attrv)
+void goog_td_e(const char* args, const QXmlStreamAttributes* unused)
{
if (goog_segname[0] == '\\' && goog_realname) {
- goog_segment(goog_realname, attrv);
+ goog_segment(goog_realname, NULL/*unused*/);
}
goog_segname[0] = '\0';
if (goog_realname) {
return result/2;
}
-void goog_poly_e(const char* args, const char** unused)
+void goog_poly_e(const char* args, const QXmlStreamAttributes *unused)
{
long lat = 0;
long lon = 0;
desc_handle = mkshort_new_handle();
setshort_length(desc_handle, 12);
- xml_init(fname, google_map, "ISO-8859-1");
+ xml_init(fname, google_map, NULL);
}
static void
* For more information, check:
* https://developers.google.com/maps/documentation/directions/
*/
+
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
#define MYNAME "googledir"
#define MY_CBUF 4096
-#if ! HAVE_LIBEXPAT
-static void
-google_rd_init(const char* fname)
-{
- fatal(MYNAME ": This build excluded Google Maps support because expat was not installed.\n");
-}
-
-static void
-google_read(void)
-{
-}
-#else
-
static xg_callback goog_points, goog_poly_e;
static xg_callback goog_instr;
};
void
-goog_points(const char* args, const char** unused)
+goog_points(const char* args, const QXmlStreamAttributes* unused)
{
if (args) {
if (encoded_points) {
}
void
-goog_instr(const char* args, const char** unused)
+goog_instr(const char* args, const QXmlStreamAttributes* unused)
{
if (args) {
if (instructions) {
}
static void
-goog_poly_e(const char* args, const char** unused)
+goog_poly_e(const char* args, const QXmlStreamAttributes* unused)
{
long lat = 0;
long lon = 0;
routehead->rte_name = (char*) xstrdup("overview");
routehead->rte_desc = (char*) xstrdup("Overview");
} else {
- goog_step++;
+ goog_step++;
xasprintf(&routehead->rte_name, "step%03d", goog_step);
if (instructions == NULL) {
xasprintf(&routehead->rte_desc, "Step %d", goog_step);
} else {
utf_string utf;
utf.is_html = 1;
- utf.utfstring = instructions;
+ utf.utfstring = QString::fromUtf8(instructions);
routehead->rte_desc = strip_html(&utf);
xfree(instructions);
instructions = NULL;
- }
+ }
}
route_add_head(routehead);
desc_handle = mkshort_new_handle();
setshort_length(desc_handle, 12);
- xml_init(fname, google_map, "ISO-8859-1");
+ // leave default of UTF-8 unless xml file overrides with encoding=
+ xml_init(fname, google_map, NULL);
}
static void
instructions = NULL;
}
}
-#endif
static void
google_rd_deinit(void)
ofd = gbfopen(fname, "wb", MYNAME);
oqfile.open(ofd->handle.std, QIODevice::WriteOnly);
- // This is ia bit of a lie. QXMLStreamWriter will pass everything
- // through the QTextCodec on the way out and that defaults to UTF-8.
- // Since we have so many C Strings in out output right now and those
- // are already UTF-8 encoded via CET, if we don't outsmart that, we
- // get double encoding.
- writer.setCodec("ISO 8859-1");
-
writer.setAutoFormattingIndent(2);
- // Technically, XML (and therefore GPX) defaults ot UTF-8, so we should not
- // have to declare this. For compatibility with the existing Qt writer,
- // we do...
- // writer.setCodec("UTF-8");
- // writer.writeStartDocument();
- writer.writeProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
-
+ writer.setCodec("UTF-8");
+ writer.writeStartDocument();
}
static void
// file. Filter that out in the two fields below... Ideally, we should
// probably filter that in the input rather than here.
- QString desc = waypointp->description;
+ QString desc = QString::fromUtf8(waypointp->description);
desc = desc.replace(QRegExp("[\014-\032]"), " ");
writer.writeOptionalTextElement("cmt", desc);
if (waypointp->notes && waypointp->notes[0]) {
- QString note = waypointp->notes;
+ QString note = QString::fromUtf8(waypointp->notes);
note = note.replace(QRegExp("[\014-\032]"), " ");
writer.writeTextElement("desc", note);
} else {
- writer.writeOptionalTextElement("desc", waypointp->description);
+ writer.writeOptionalTextElement("desc", QString::fromUtf8(waypointp->description));
}
write_gpx_url(waypointp);
current_trk_head = rte;
writer.writeStartElement("trk");
- writer.writeOptionalTextElement("name", rte->rte_name);
- writer.writeOptionalTextElement("desc", rte->rte_desc);
+ writer.writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name));
+ writer.writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc));
if (rte->rte_num) {
writer.writeTextElement("number", QString::number(rte->rte_num));
}
{
fs_xml* fs_gpx;
writer.writeStartElement("rte");
- writer.writeOptionalTextElement("name", rte->rte_name);
- writer.writeOptionalTextElement("desc", rte->rte_desc);
+ writer.writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name));
+ writer.writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc));
if (rte->rte_num) {
writer.writeTextElement("number", QString::number(rte->rte_num));
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
}
void
-gtc_trk_s(const char* unused, const char** attrv)
+gtc_trk_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
{
trk_head = route_head_alloc();
track_add_head(trk_head);
}
void
-gtc_trk_ident(const char* args, const char** unused)
+gtc_trk_ident(const char* args, const QXmlStreamAttributes* unused)
{
trk_head->rte_name = xstrdup(args);
}
void
-gtc_trk_lap_s(const char* unused, const char** attrv)
+gtc_trk_lap_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
{
lap_ct++;
lap_s = 1;
}
void
-gtc_trk_lap_e(const char* unused, const char** attrv)
+gtc_trk_lap_e(const char* unused, const QXmlStreamAttributes* unusedattrs)
{
lap_s = 0;
}
void
-gtc_trk_pnt_s(const char* unused, const char** attrv)
+gtc_trk_pnt_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
{
wpt_tmp = waypt_new();
}
void
-gtc_trk_pnt_e(const char* args, const char** unused)
+gtc_trk_pnt_e(const char* args, const QXmlStreamAttributes* unusedd)
{
if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
if (lap_s) {
}
void
-gtc_trk_utc(const char* args, const char** unused)
+gtc_trk_utc(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->creation_time = xml_parse_time(args);
}
void
-gtc_trk_lat(const char* args, const char** unused)
+gtc_trk_lat(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->latitude = atof(args);
}
void
-gtc_trk_long(const char* args, const char** unused)
+gtc_trk_long(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->longitude = atof(args);
}
void
-gtc_trk_alt(const char* args, const char** unused)
+gtc_trk_alt(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->altitude = atof(args);
}
void
-gtc_trk_dist(const char* args, const char** unused)
+gtc_trk_dist(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->odometer_distance = atof(args);
}
void
-gtc_trk_hr(const char* args, const char** unused)
+gtc_trk_hr(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->heartrate = atoi(args);
}
void
-gtc_trk_cad(const char* args, const char** unused)
+gtc_trk_cad(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->cadence = atoi(args);
}
void
-gtc_trk_pwr(const char* args, const char** unused)
+gtc_trk_pwr(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->power = atof(args);
}
void
-gtc_trk_spd(const char* args, const char** unused)
+gtc_trk_spd(const char* args, const QXmlStreamAttributes* unusedd)
{
WAYPT_SET(wpt_tmp, speed, atof(args));
}
void
-gtc_wpt_crs_s(const char* unused, const char** attrv)
+gtc_wpt_crs_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
{
wpt_tmp = waypt_new();
}
void
-gtc_wpt_crs_e(const char* args, const char** unused)
+gtc_wpt_crs_e(const char* args, const QXmlStreamAttributes* unusedd)
{
if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
waypt_add(wpt_tmp);
}
void
-gtc_wpt_pnt_s(const char* unused, const char** attrv)
+gtc_wpt_pnt_s(const char* unused, const QXmlStreamAttributes* unusedattrs)
{
wpt_tmp = waypt_new();
lap_ct++;
}
void
-gtc_wpt_pnt_e(const char* args, const char** unused)
+gtc_wpt_pnt_e(const char* args, const QXmlStreamAttributes* unusedd)
{
if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
/* Add the begin position of a CourseLap as
}
void
-gtc_wpt_ident(const char* args, const char** unused)
+gtc_wpt_ident(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->shortname = xstrdup(args);
/* Set also as notes for compatibility with garmin usb format */
}
void
-gtc_wpt_lat(const char* args, const char** unused)
+gtc_wpt_lat(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->latitude = atof(args);
}
void
-gtc_wpt_long(const char* args, const char** unused)
+gtc_wpt_long(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->longitude = atof(args);
}
void
-gtc_wpt_icon(const char* args, const char** unused)
+gtc_wpt_icon(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->icon_descr = args;
}
void
-gtc_wpt_notes(const char* args, const char** unused)
+gtc_wpt_notes(const char* args, const QXmlStreamAttributes* unusedd)
{
wpt_tmp->description = xstrdup(args);
}
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
}
static
-void ht_wpt_s(const char* args, const char** unused)
+void ht_wpt_s(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp = waypt_new();
}
static
-void ht_ident(const char* args, const char** unused)
+void ht_ident(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->shortname = xstrdup(args);
}
static
-void ht_sym(const char* args, const char** unused)
+void ht_sym(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->icon_descr = args;
}
static
-void ht_lat(const char* args, const char** unused)
+void ht_lat(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->latitude = atof(args);
}
static
-void ht_long(const char* args, const char** unused)
+void ht_long(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->longitude = atof(args);
}
static
-void ht_alt(const char* args, const char** unused)
+void ht_alt(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->altitude = atof(args);
}
static
-void ht_wpt_e(const char* args, const char** unused)
+void ht_wpt_e(const char* args, const QXmlStreamAttributes* unused)
{
waypt_add(wpt_tmp);
wpt_tmp = NULL;
}
static
-void ht_trk_s(const char* args, const char** unused)
+void ht_trk_s(const char* args, const QXmlStreamAttributes* unused)
{
trk_head = route_head_alloc();
track_add_head(trk_head);
}
static
-void ht_trk_e(const char* args, const char** unused)
+void ht_trk_e(const char* args, const QXmlStreamAttributes* unused)
{
}
static
-void ht_trk_ident(const char* args, const char** unused)
+void ht_trk_ident(const char* args, const QXmlStreamAttributes* unused)
{
trk_head->rte_name = xstrdup(args);
}
static
-void ht_trk_pnt_s(const char* args, const char** unused)
+void ht_trk_pnt_s(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp = waypt_new();
}
static
-void ht_trk_pnt_e(const char* args, const char** unused)
+void ht_trk_pnt_e(const char* args, const QXmlStreamAttributes* unused)
{
track_add_wpt(trk_head, wpt_tmp);
}
static
-void ht_trk_utc(const char* args, const char** unused)
+void ht_trk_utc(const char* args, const QXmlStreamAttributes* unused)
{
struct tm tm;
time_t utc;
}
static
-void ht_trk_lat(const char* args, const char** unused)
+void ht_trk_lat(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->latitude = atof(args);
}
static
-void ht_trk_long(const char* args, const char** unused)
+void ht_trk_long(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->longitude = atof(args);
}
static
-void ht_trk_alt(const char* args, const char** unused)
+void ht_trk_alt(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->altitude = atof(args);
}
#include <stdlib.h>
#include <time.h>
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
static xg_callback ignr_etape_begin, ignr_etape_end;
static void
-ignr_start(const char* args, const char** attrv)
+ignr_start(const char* args, const QXmlStreamAttributes* attrv)
{
ignr_xml_error((track != NULL));
}
static void
-ignr_nb_etapes(const char* args, const char** attrv)
+ignr_nb_etapes(const char* args, const QXmlStreamAttributes* attrv)
{
xmlpoints = atoi(args);
}
static void
-ignr_descr(const char* args, const char** attrv)
+ignr_descr(const char* args, const QXmlStreamAttributes* attrv)
{
ignr_xml_error((track == NULL));
}
static void
-ignr_etape_begin(const char* args, const char** attrv)
+ignr_etape_begin(const char* args, const QXmlStreamAttributes* attrv)
{
ignr_xml_error((wpt != NULL));
}
static void
-ignr_etape_end(const char* args, const char** attrv)
+ignr_etape_end(const char* args, const QXmlStreamAttributes* attrv)
{
ignr_xml_error((track == NULL) || (wpt == NULL));
}
static void
-ignr_etape_pos(const char* args, const char** attrv)
+ignr_etape_pos(const char* args, const QXmlStreamAttributes* attrv)
{
ignr_xml_error((wpt == NULL) || (args == NULL));
}
static void
-ignr_etape_alt(const char* args, const char** attrv)
+ignr_etape_alt(const char* args, const QXmlStreamAttributes* attrv)
{
ignr_xml_error((wpt == NULL));
if (args == NULL) {
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
static char* name, *text;
-#if ! HAVE_LIBEXPAT
-void
-ikt_rd_init(const char* fname)
-{
- fatal(MYNAME ": This build excluded \" MYNAME \" support because expat was not installed.\n");
-}
-
-void
-ikt_read(void)
-{
-}
-
-static void
-ikt_object_end(void)
-{
-}
-
-#else
-
static route_head* track;
static waypoint* waypt;
}
static void
-iktobj_waypt(const char* args, const char** attrv)
+iktobj_waypt(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
-
- while (*avp) {
- if (strcmp(avp[0], "X") == 0) {
- waypt->longitude = atof(avp[1]);
- } else if (strcmp(avp[0], "Y") == 0) {
- waypt->latitude = atof(avp[1]);
- }
- avp+=2;
+ if (attrv->hasAttribute("X")) {
+ waypt->longitude = attrv->value("X").toString().toDouble();
+ }
+ if (attrv->hasAttribute("Y")) {
+ waypt->latitude = attrv->value("Y").toString().toDouble();
}
}
static void
-iktobj_trkpt(const char* args, const char** attrv)
+iktobj_trkpt(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
-
waypt = waypt_new();
- while (*avp) {
- if (strcmp(avp[0], "X") == 0) {
- waypt->longitude = atof(avp[1]);
- } else if (strcmp(avp[0], "Y") == 0) {
- waypt->latitude = atof(avp[1]);
- }
- avp+=2;
- }
+ iktobj_waypt(args, attrv);
track_add_wpt(track, waypt);
waypt = NULL;
}
static void
-iktobj_name(const char* args, const char** unused)
+iktobj_name(const char* args, const QXmlStreamAttributes* unused)
{
name = xstrdup(args);
}
static void
-iktobj_text(const char* args, const char** unused)
+iktobj_text(const char* args, const QXmlStreamAttributes* unused)
{
text = xstrdup(args);
}
static void
-iktobj_type(const char* args, const char** unused)
+iktobj_type(const char* args, const QXmlStreamAttributes* unused)
{
ikt_object_end();
xml_read();
}
-#endif
-
static void
ikt_rd_deinit(void)
{
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
#include "jeeps/gpsmath.h"
#define MYNAME "xol"
-#if ! HAVE_LIBEXPAT
-void
-jogmap_rd_init(const char* fname)
-{
- fatal(MYNAME ": This build excluded \"" MYNAME "\" support because expat was not installed.\n");
-}
-
-void
-jogmap_read(void)
-{
-}
-
-#else
-
// static xg_callback jogmap_shape, xol_shape_end;
// static xg_callback jogmap_waypt, xol_overlay;
static void
-jogmap_markers(const char* args, const char** attrv)
+jogmap_markers(const char* args, const QXmlStreamAttributes* attrv)
{
trk = route_head_alloc();
track_add_head(trk);
}
static void
-jogmap_marker(const char* args, const char** attrv)
+jogmap_marker(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
waypoint* wpt = waypt_new();
- while (*avp) {
- if (strcmp(avp[0], "lat") == 0) {
- sscanf(avp[1], "%lf",
- &wpt->latitude);
- } else if (strcmp(avp[0], "lng") == 0) {
- sscanf(avp[1], "%lf",
- &wpt->longitude);
- }
+ if (attrv->hasAttribute("lat")) {
+ wpt->latitude = attrv->value("lat").toString().toDouble();
+ }
- avp+=2;
+ if (attrv->hasAttribute("lng")) {
+ wpt->longitude = attrv->value("lng").toString().toDouble();
}
if (trk) {
xml_read();
}
-#endif
-
static void
jogmap_rd_deinit(void)
{
*/
#include <math.h>
#include <QtCore/QRegExp>
+#include <QtCore/QXmlStreamAttributes>
#ifdef __WIN32__
# include <windows.h>
static const char* posnfilename;
static char* posnfilenametmp;
-static gbfile* ofd;
-static QString ostring;
-static gpsbabel::XmlStreamWriter* writer;
+static gbfile* ofd = NULL;
+static QFile oqfile;
+static gpsbabel::XmlStreamWriter* writer = new gpsbabel::XmlStreamWriter(oqfile);
typedef enum {
kmlpt_unknown,
NULL,
};
-void wpt_s(const char* args, const char** unused)
+void wpt_s(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp = waypt_new();
wpt_tmp_queued = 0;
}
-void wpt_e(const char* args, const char** unused)
+void wpt_e(const char* args, const QXmlStreamAttributes* unused)
{
if (wpt_tmp_queued) {
waypt_add(wpt_tmp);
wpt_tmp_queued = 0;
}
-void wpt_name(const char* args, const char** unused)
+void wpt_name(const char* args, const QXmlStreamAttributes* unused)
{
if (args) {
wpt_tmp->shortname = xstrdup(args);
}
}
-void wpt_desc(const char* args, const char** unused)
+void wpt_desc(const char* args, const QXmlStreamAttributes* unused)
{
if (args) {
char* tmp, *c;
}
}
-void wpt_time(const char* args, const char** unused)
+void wpt_time(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->SetCreationTime(xml_parse_time(args));
}
-void wpt_coord(const char* args, const char** attrv)
+void wpt_coord(const char* args, const QXmlStreamAttributes* attrv)
{
int n = 0;
double lat, lon, alt;
wpt_tmp_queued = 1;
}
-void wpt_icon(const char* args, const char** unused)
+void wpt_icon(const char* args, const QXmlStreamAttributes* unused)
{
if (wpt_tmp) {
wpt_tmp->icon_descr = args;
}
}
-void trk_coord(const char* args, const char** attrv)
+void trk_coord(const char* args, const QXmlStreamAttributes* attrv)
{
int consumed = 0;
double lat, lon, alt;
* Reduce race conditions with network read link.
*/
ofd = gbfopen(fname, "w", MYNAME);
+ oqfile.open(ofd->handle.std, QIODevice::WriteOnly);
- writer = new gpsbabel::XmlStreamWriter(ostring);
writer->setAutoFormattingIndent(2);
- // Technically, XML (and therefore KML) defaults ot UTF-8, so we should not
- // have to declare this. For compatibility with the existing Qt writer,
- // we do...
- //writer.setCodec("UTF-8");
- //writer.writeStartDocument();
-
+ writer->setCodec("UTF-8");
}
/*
* 30% of our output file is whitespace. Since parse time
* matters in this mode, turn the pretty formatting off.
*/
- writer = new gpsbabel::XmlStreamWriter(ostring);
writer->setAutoFormatting(false);
+ writer->setCodec("UTF-8");
max_position_points = atoi(opt_max_position_points);
}
kml_wr_deinit(void)
{
writer->writeEndDocument();
-
- // FIXME: Nuke illegal xml characters.
- // If we have done things right this shouldn't be necessary.
- ostring.replace(QRegExp("[\001-\010]"), " ").replace(QRegExp("[\013-\014]"), " ").replace(QRegExp("[\016-\037]"), " ");
-
- gbfputs(ostring, ofd);
+ oqfile.close();
gbfclose(ofd);
if (posnfilenametmp) {
#endif
rename(posnfilenametmp, posnfilename);
}
- delete writer;
- writer = NULL;
- ostring.clear();
ofd = NULL;
}
if (export_points) {
writer->writeStartElement("Placemark");
if (atoi(opt_labels)) {
- writer->writeOptionalTextElement("name", waypointp->shortname);
+ writer->writeOptionalTextElement("name", QString::fromUtf8(waypointp->shortname));
}
writer->writeEmptyElement("snippet");
kml_output_description(waypointp);
{
char import_time[100];
time_t now;
- const global_trait* traits = get_traits();
+ const global_trait* traits = get_traits();
// Parse options
export_lines = (0 == strcmp("1", opt_export_lines));
trackdirection = (!! strcmp("0", opt_trackdirection));
line_width = atol(opt_line_width);
- writer->writeProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
+ writer->writeStartDocument();
// FIXME: This write of a blank line is needed for Qt 4.6 (as on Centos 6.3)
// to include just enough whitespace between <xml/> and <gpx...> to pass
// diff -w. It's here for now to shim compatibility with our zillion
* we don't implement that at this time in GPSBabel.
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
static void
-lmx_lm_start(const char* args, const char** unused)
+lmx_lm_start(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp = waypt_new();
}
static void
-lmx_lm_end(const char* args, const char** unused)
+lmx_lm_end(const char* args, const QXmlStreamAttributes* unused)
{
waypt_add(wpt_tmp);
}
static void
-lmx_lm_lat(const char* args, const char** unused)
+lmx_lm_lat(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->latitude = atof(args);
}
static void
-lmx_lm_lon(const char* args, const char** unused)
+lmx_lm_lon(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->longitude = atof(args);
}
static void
-lmx_lm_alt(const char* args, const char** unused)
+lmx_lm_alt(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->altitude = atof(args);
}
static void
-lmx_lm_name(const char* args, const char** unused)
+lmx_lm_name(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->shortname = xstrdup(args);
}
static void
-lmx_lm_desc(const char* args, const char** unused)
+lmx_lm_desc(const char* args, const QXmlStreamAttributes* unused)
{
wpt_tmp->description = xstrdup(args);
}
static void
-lmx_lm_mlink_s(const char* args, const char** unused)
+lmx_lm_mlink_s(const char* args, const QXmlStreamAttributes* unused)
{
urllink = urllinkt = QString();
}
static void
-lmx_lm_link(const char* args, const char** unused)
+lmx_lm_link(const char* args, const QXmlStreamAttributes* unused)
{
urllink = args;
}
static void
-lmx_lm_linkt(const char* args, const char** unused)
+lmx_lm_linkt(const char* args, const QXmlStreamAttributes* unused)
{
urllinkt = args;
}
static void
-lmx_lm_mlink_e(const char* args, const char** unused)
+lmx_lm_mlink_e(const char* args, const QXmlStreamAttributes* unused)
{
waypt_add_url(wpt_tmp, urllink, urllinkt);
}
#include <ctype.h>
#include <math.h>
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "csv_util.h"
#include "xmlgeneric.h"
*/
+#include <QtCore/QTextCodec>
#include "defs.h"
#include "filterdefs.h"
signed int wpt_ct_bak, rte_ct_bak, trk_ct_bak; /* #ifdef UTF8_SUPPORT */
arg_stack_t* arg_stack = NULL;
+ QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
+
global_opts.objective = wptdata;
global_opts.masked_objective = NOTHINGMASK; /* this makes the default mask behaviour slightly different */
global_opts.charset = NULL;
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "avltree.h"
#include "xmlgeneric.h"
#define MYNAME "osm"
-static avltree_t* waypoints; /* AVL tree */
+static QMap<QString, const waypoint*> waypoints;
static avltree_t* keys = NULL;
static avltree_t* values = NULL;
static void
-osm_node_end(const char* args, const char** unused)
+osm_node_end(const char* args, const QXmlStreamAttributes* unused)
{
if (wpt) {
if (wpt->wpt_flags.fmt_use) {
static void
-osm_node(const char* args, const char** attrv)
+osm_node(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
-
wpt = waypt_new();
- while (*avp) {
- if (strcmp(avp[0], "id") == 0) {
- xasprintf(&wpt->description, "osm-id %s", avp[1]);
- if (! avltree_insert(waypoints, avp[1], (void*)wpt)) {
- warning(MYNAME ": Duplicate osm-id %s!\n", avp[1]);
- } else {
- wpt->wpt_flags.fmt_use = 1;
- }
- } else if (strcmp(avp[0], "user") == 0) ;
- else if (strcmp(avp[0], "lat") == 0) {
- wpt->latitude = atof(avp[1]);
- } else if (strcmp(avp[0], "lon") == 0) {
- wpt->longitude = atof(avp[1]);
- } else if (strcmp(avp[0], "timestamp") == 0) {
- wpt->creation_time = xml_parse_time(avp[1]);
+ if (attrv->hasAttribute("id")) {
+ QString atstr = attrv->value("id").toString();
+
+ xasprintf(&wpt->description, "osm-id %s", CSTR(atstr));
+ if (waypoints.contains(atstr)) {
+ warning(MYNAME ": Duplicate osm-id %s!\n", CSTR(atstr));
+ } else {
+ waypoints.insert(atstr, wpt);
+ wpt->wpt_flags.fmt_use = 1;
}
+ }
+
+ // if (attrv->hasAttribute("user")) ; // ignored
- avp += 2;
+ if (attrv->hasAttribute("lat")) {
+ wpt->latitude = attrv->value("lat").toString().toDouble();
+ }
+ if (attrv->hasAttribute("lon")) {
+ wpt->longitude = attrv->value("lon").toString().toDouble();
+ }
+
+ if (attrv->hasAttribute("timestamp")) {
+ QByteArray tsutf8 = attrv->value("timestamp").toString().toUtf8();
+ wpt->creation_time = xml_parse_time(tsutf8.constData());
}
}
static void
-osm_node_tag(const char* args, const char** attrv)
+osm_node_tag(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
+ QByteArray qkey, qvalue;
const char* key = "", *value = "";
char* str;
signed char ikey;
- while (*avp) {
- if (strcmp(avp[0], "k") == 0) {
- key = avp[1];
- } else if (strcmp(avp[0], "v") == 0) {
- value = avp[1];
- }
- avp+=2;
+ if (attrv->hasAttribute("k")) {
+ qkey = attrv->value("k").toString().toUtf8();
+ key = qkey.constData();
+ }
+ if (attrv->hasAttribute("v")) {
+ qvalue = attrv->value("v").toString().toUtf8();
+ value = qvalue.constData();
}
str = osm_strip_html(value);
static void
-osm_way(const char* args, const char** attrv)
+osm_way(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
-
rte = route_head_alloc();
- while (*avp) {
- if (strcmp(avp[0], "id") == 0) {
- xasprintf(&rte->rte_desc, "osm-id %s", avp[1]);
- }
- avp += 2;
+ if (attrv->hasAttribute("id")) {
+ xasprintf(&rte->rte_desc, "osm-id %s",
+ attrv->value("id").toString().toUtf8().constData());
}
}
static void
-osm_way_nd(const char* args, const char** attrv)
+osm_way_nd(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
-
- while (*avp) {
- if (strcmp(avp[0], "ref") == 0) {
- waypoint* tmp;
- if (avltree_find(waypoints, avp[1], (const void**)&tmp)) {
- tmp = waypt_dupe(tmp);
- route_add_wpt(rte, tmp);
- } else {
- warning(MYNAME ": Way reference id \"%s\" wasn't listed under nodes!\n", avp[1]);
- }
+ if (attrv->hasAttribute("ref")) {
+ QString atstr = attrv->value("ref").toString();
+ waypoint* tmp;
+ const waypoint* ctmp;
+
+ if (waypoints.contains(atstr)) {
+ ctmp = waypoints.value(atstr);
+ tmp = waypt_dupe(ctmp);
+ route_add_wpt(rte, tmp);
+ } else {
+ warning(MYNAME ": Way reference id \"%s\" wasn't listed under nodes!\n", CSTR(atstr));
}
- avp += 2;
}
}
static void
-osm_way_tag(const char* args, const char** attrv)
+osm_way_tag(const char* args, const QXmlStreamAttributes* attrv)
{
- const char** avp = &attrv[0];
+ QByteArray qkey, qvalue;
const char* key = "", *value = "";
char* str;
- while (*avp) {
- if (strcmp(avp[0], "k") == 0) {
- key = avp[1];
- } else if (strcmp(avp[0], "v") == 0) {
- value = avp[1];
- }
- avp += 2;
+ if (attrv->hasAttribute("k")) {
+ qkey = attrv->value("k").toString().toUtf8();
+ key = qkey.constData();
+ }
+ if (attrv->hasAttribute("v")) {
+ qvalue = attrv->value("v").toString().toUtf8();
+ value = qvalue.constData();
}
str = osm_strip_html(value);
}
static void
-osm_way_end(const char* args, const char** unused)
+osm_way_end(const char* args, const QXmlStreamAttributes* unused)
{
if (rte) {
route_add_head(rte);
wpt_loaded = 0;
rte_loaded = 0;
- waypoints = avltree_init(0, MYNAME);
+ waypoints.clear();
if (! keys) {
osm_features_init();
}
osm_rd_deinit(void)
{
xml_deinit();
- avltree_done(waypoints);
+ waypoints.clear();
}
/*******************************************************************************/
}
}
+static QString
+osm_name_from_wpt(const waypoint* wpt)
+{
+ QString name = QString("%1\01%2\01%3")
+ .arg((wpt->shortname) ? wpt->shortname : "")
+ .arg(wpt->latitude)
+ .arg(wpt->longitude);
+ return name;
+}
+
static void
osm_waypt_disp(const waypoint* wpt)
{
- char* buff;
+ QString name = osm_name_from_wpt(wpt);
- xasprintf(&buff, "%s\01%f\01%f", (wpt->shortname) ? wpt->shortname : "",
- wpt->latitude, wpt->longitude);
-
- if (avltree_insert(waypoints, buff, (const void*) wpt)) {
- int* id;
+ if (waypoints.contains(name)) {
+ return;
+ }
- id = (int*) xmalloc(sizeof(*id));
- *id = --node_id;
- ((waypoint*)(wpt))->extra_data = id;
+ waypoints.insert(name, wpt);
- gbfprintf(fout, " <node id='%d' visible='true' lat='%0.7f' lon='%0.7f'", *id, wpt->latitude, wpt->longitude);
- if (wpt->creation_time) {
- QString time_string = wpt->CreationTimeXML();
- gbfprintf(fout, " timestamp='%s'", qPrintable(time_string));
- }
- gbfprintf(fout, ">\n");
+ int* id;
- if (wpt->hdop) {
- gbfprintf(fout, " <tag k='gps:hdop' v='%f' />\n", wpt->hdop);
- }
- if (wpt->vdop) {
- gbfprintf(fout, " <tag k='gps:vdop' v='%f' />\n", wpt->vdop);
- }
- if (wpt->pdop) {
- gbfprintf(fout, " <tag k='gps:pdop' v='%f' />\n", wpt->pdop);
- }
- if (wpt->sat > 0) {
- gbfprintf(fout, " <tag k='gps:sat' v='%d' />\n", wpt->sat);
- }
+ id = (int*) xmalloc(sizeof(*id));
+ *id = --node_id;
+ ((waypoint*)(wpt))->extra_data = id;
- switch (wpt->fix) {
- case fix_2d:
- gbfprintf(fout, " <tag k='gps:fix' v='2d' />\n");
- break;
- case fix_3d:
- gbfprintf(fout, " <tag k='gps:fix' v='3d' />\n");
- break;
- case fix_dgps:
- gbfprintf(fout, " <tag k='gps:fix' v='dgps' />\n");
- break;
- case fix_pps:
- gbfprintf(fout, " <tag k='gps:fix' v='pps' />\n");
- break;
- case fix_none:
- gbfprintf(fout, " <tag k='gps:fix' v='none' />\n");
- break;
- case fix_unknown:
- default:
- break;
- }
+ gbfprintf(fout, " <node id='%d' visible='true' lat='%0.7f' lon='%0.7f'", *id, wpt->latitude, wpt->longitude);
+ if (wpt->creation_time) {
+ QString time_string = wpt->CreationTimeXML();
+ gbfprintf(fout, " timestamp='%s'", qPrintable(time_string));
+ }
+ gbfprintf(fout, ">\n");
- if (strlen(created_by) !=0) {
- gbfprintf(fout, " <tag k='created_by' v='%s",created_by);
- if (gpsbabel_time != 0)
- if (strcmp("GPSBabel",created_by)==0) {
- gbfprintf(fout, "-%s", gpsbabel_version);
- }
- gbfprintf(fout, "'/>\n");
- }
+ if (wpt->hdop) {
+ gbfprintf(fout, " <tag k='gps:hdop' v='%f' />\n", wpt->hdop);
+ }
+ if (wpt->vdop) {
+ gbfprintf(fout, " <tag k='gps:vdop' v='%f' />\n", wpt->vdop);
+ }
+ if (wpt->pdop) {
+ gbfprintf(fout, " <tag k='gps:pdop' v='%f' />\n", wpt->pdop);
+ }
+ if (wpt->sat > 0) {
+ gbfprintf(fout, " <tag k='gps:sat' v='%d' />\n", wpt->sat);
+ }
- osm_write_tag("name", wpt->shortname);
- osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description);
- if (!wpt->icon_descr.isNull()) {
- osm_disp_feature(wpt);
- }
+ switch (wpt->fix) {
+ case fix_2d:
+ gbfprintf(fout, " <tag k='gps:fix' v='2d' />\n");
+ break;
+ case fix_3d:
+ gbfprintf(fout, " <tag k='gps:fix' v='3d' />\n");
+ break;
+ case fix_dgps:
+ gbfprintf(fout, " <tag k='gps:fix' v='dgps' />\n");
+ break;
+ case fix_pps:
+ gbfprintf(fout, " <tag k='gps:fix' v='pps' />\n");
+ break;
+ case fix_none:
+ gbfprintf(fout, " <tag k='gps:fix' v='none' />\n");
+ break;
+ case fix_unknown:
+ default:
+ break;
+ }
- osm_write_opt_tag(opt_tagnd);
+ if (strlen(created_by) !=0) {
+ gbfprintf(fout, " <tag k='created_by' v='%s",created_by);
+ if (gpsbabel_time != 0)
+ if (strcmp("GPSBabel",created_by)==0) {
+ gbfprintf(fout, "-%s", gpsbabel_version);
+ }
+ gbfprintf(fout, "'/>\n");
+ }
- gbfprintf(fout, " </node>\n");
+ osm_write_tag("name", wpt->shortname);
+ osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description);
+ if (!wpt->icon_descr.isNull()) {
+ osm_disp_feature(wpt);
}
- xfree(buff);
+ osm_write_opt_tag(opt_tagnd);
+
+ gbfprintf(fout, " </node>\n");
}
static void
static void
osm_rtept_disp(const waypoint* wpt_ref)
{
- char* buff;
- waypoint* wpt;
+ QString name = osm_name_from_wpt(wpt_ref);
+ const waypoint* wpt;
if (skip_rte) {
return;
}
- xasprintf(&buff, "%s\01%f\01%f", (wpt_ref->shortname) ? wpt_ref->shortname : "",
- wpt_ref->latitude, wpt_ref->longitude);
-
- if (avltree_find(waypoints, buff, (const void**) &wpt)) {
+ if (waypoints.contains(name)) {
+ wpt = waypoints.value(name);
int* id = (int*) wpt->extra_data;
gbfprintf(fout, " <nd ref='%d'/>\n", *id);
}
-
- xfree(buff);
}
static void
fout = gbfopen(fname, "w", MYNAME);
osm_init_icons();
- waypoints = avltree_init(0, MYNAME);
+ waypoints.clear();
node_id = 0;
}
route_disp_all(NULL, NULL, osm_release_ids);
track_disp_all(NULL, NULL, osm_release_ids);
- avltree_done(waypoints);
+ waypoints.clear();
}
static void
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
fatal("Writing file of type %s is not supported\n", MYNAME);
}
-void wpt_s(const char *args, const char **unused)
+void wpt_s(const char *args, const QXmlStreamAttributes* unused)
{
if (isFirst == 1) {
wpt_from = waypt_new();
wpt_to = waypt_new();
}
-void wpt_e(const char *args, const char **unused)
+void wpt_e(const char *args, const QXmlStreamAttributes* unused)
{
if (isFirst == 1) {
route_add_wpt(route, wpt_from);
wpt_to = NULL;
}
-void wpt_from_lat(const char *args, const char **unused)
+void wpt_from_lat(const char *args, const QXmlStreamAttributes* unused)
{
if (wpt_from != NULL) {
wpt_from->latitude = atof(args);
}
}
-void wpt_from_lon(const char *args, const char **unused)
+void wpt_from_lon(const char *args, const QXmlStreamAttributes* unused)
{
if (wpt_from != NULL) {
wpt_from->longitude = atof(args);
}
}
-void wpt_from_name(const char *args, const char **unused)
+void wpt_from_name(const char *args, const QXmlStreamAttributes* unused)
{
if (wpt_from != NULL) {
wpt_from->shortname = xstrappend(wpt_from->shortname, args);
}
}
-void wpt_from_elev(const char *args, const char **unused)
+void wpt_from_elev(const char *args, const QXmlStreamAttributes* unused)
{
if (wpt_from != NULL) {
wpt_from->altitude = FEET_TO_METERS(atof(args));
}
}
-void wpt_to_lat(const char *args, const char **unused)
+void wpt_to_lat(const char *args, const QXmlStreamAttributes* unused)
{
wpt_to->latitude = atof(args);
}
-void wpt_to_lon(const char *args, const char **unused)
+void wpt_to_lon(const char *args, const QXmlStreamAttributes* unused)
{
wpt_to->longitude = atof(args);
}
-void wpt_to_name(const char *args, const char **unused)
+void wpt_to_name(const char *args, const QXmlStreamAttributes* unused)
{
wpt_to->shortname = xstrappend(wpt_to->shortname, args);
}
-void wpt_to_elev(const char *args, const char **unused)
+void wpt_to_elev(const char *args, const QXmlStreamAttributes* unused)
{
dest_altitude = FEET_TO_METERS(atof(args));
}
-void wpt_altitude(const char *args, const char **attrv)
+void wpt_altitude(const char *args, const QXmlStreamAttributes* attrv)
{
int isFeet = 0;
- const char **avp = &attrv[0];
- while (*avp) {
- if (0 == strcmp(avp[0], "Value")) {
- wpt_to->altitude = atof(avp[1]);
- }
- if (0 == strcmp(avp[0], "Unit")) {
- isFeet = strcmp(avp[1], "ft") == 0 ? 1 : 0;
- }
- avp += 2;
+
+ if (attrv->hasAttribute("Value")) {
+ wpt_to->altitude = attrv->value("Value").toString().toDouble();
+ }
+ if (attrv->hasAttribute("Unit")) {
+ isFeet = (attrv->value("Unit") == "ft");
}
if (isFeet) {
wpt_to->altitude = FEET_TO_METERS(wpt_to->altitude);
</rte>
<rte>
<name>step004</name>
- <desc>Slight right onto Pl. LapÃ\83¨rouse</desc>
+ <desc>Slight right onto Pl. Lapèrouse</desc>
<rtept lat="43.925620000" lon="2.145510000">
<name>RPT013</name>
</rtept>
</rte>
<rte>
<name>step005</name>
- <desc>Slight left to stay on Pl. LapÃ\83¨rouse</desc>
+ <desc>Slight left to stay on Pl. Lapèrouse</desc>
<rtept lat="43.925830000" lon="2.145030000">
<name>RPT020</name>
</rtept>
</rte>
<rte>
<name>step006</name>
- <desc>Continue onto Av. GÃ\83©nÃ\83©ral de Gaulle</desc>
+ <desc>Continue onto Av. Général de Gaulle</desc>
<rtept lat="43.924200000" lon="2.144330000">
<name>RPT042</name>
</rtept>
</rte>
<rte>
<name>step007</name>
- <desc>At the roundabout, take the 1st exit onto Av. MarÃ\83©chal Joffre</desc>
+ <desc>At the roundabout, take the 1st exit onto Av. Maréchal Joffre</desc>
<rtept lat="43.922490000" lon="2.142280000">
<name>RPT048</name>
</rtept>
</rte>
<rte>
<name>step009</name>
- <desc>Turn right onto Av. FranÃ\83§ois Verdier/D988Continue to follow D988</desc>
+ <desc>Turn right onto Av. François Verdier/D988Continue to follow D988</desc>
<rtept lat="43.919590000" lon="2.135000000">
<name>RPT089</name>
</rtept>
</rte>
<rte>
<name>step013</name>
- <desc>Keep left at the fork, follow signs for A61/PÃ\83©riphÃ\83©rique IntÃ\83©rieur/La Roseraie/Toulouse-Centre/Montpellier/Barcelone/Foix and merge onto A61Partial toll road</desc>
+ <desc>Keep left at the fork, follow signs for A61/Périphérique Intérieur/La Roseraie/Toulouse-Centre/Montpellier/Barcelone/Foix and merge onto A61Partial toll road</desc>
<rtept lat="43.638120000" lon="1.483170000">
<name>RPT1595</name>
</rtept>
</rte>
<rte>
<name>step017</name>
- <desc>Continue onto Av. LÃ\83©on Blum</desc>
+ <desc>Continue onto Av. Léon Blum</desc>
<rtept lat="43.614770000" lon="1.463970000">
<name>RPT1853</name>
</rtept>
</rte>
<rte>
<name>step021</name>
- <desc>Continue onto AllÃ\83©e Jean JaurÃ\83¨s/AllÃ\83©es Jean-JaurÃ\83¨s</desc>
+ <desc>Continue onto Allée Jean Jaurès/Allées Jean-Jaurès</desc>
<rtept lat="43.609300000" lon="1.453880000">
<name>RPT1946</name>
</rtept>
</rte>
<rte>
<name>step022</name>
- <desc>Slight left onto AllÃ\83©e PrÃ\83©sident Roosevelt</desc>
+ <desc>Slight left onto Allée Président Roosevelt</desc>
<rtept lat="43.605870000" lon="1.448620000">
<name>RPT1964</name>
</rtept>
</rte>
<rte>
<name>step023</name>
- <desc>Turn right onto Pl. du PrÃ\83©sident Thomas Wilson</desc>
+ <desc>Turn right onto Pl. du Président Thomas Wilson</desc>
<rtept lat="43.605190000" lon="1.447670000">
<name>RPT1970</name>
</rtept>
-41.87895, -87.63665, S Upper Wacker Dr
+41.87895, -87.63665, Head north from S Upper Wacker Dr
41.87924, -87.63666, \00001
41.87937, -87.63666, \00002
41.87952, -87.63667, \00003
41.88063, -87.63672, \00004
41.88126, -87.63673, \00005
41.88194, -87.63676, \00006
-41.88194, -87.63676, N Upper Wacker Dr
+41.88194, -87.63676, Continue on N Upper Wacker Dr
41.88206, -87.63676, \00008
41.88257, -87.63678, \00009
41.88301, -87.63679, \0000a
41.88519, -87.63686, \0000f
41.88542, -87.63686, \00010
41.88574, -87.63682, \00011
-41.88574, -87.63682, W Upper Wacker Dr
+41.88574, -87.63682, Bear right at W Upper Wacker Dr
41.88583, -87.63678, \00013
41.88595, -87.63666, \00014
41.88677, -87.63538, \00015
41.88677, -87.63477, \00017
41.88677, -87.63394, \00018
41.88677, -87.63249, \00019
-41.88677, -87.63249, N La Salle St
+41.88677, -87.63249, Turn left at N La Salle St
41.88696, -87.63248, \0001b
41.88710, -87.63248, \0001c
41.88780, -87.63248, \0001d
-41.88780, -87.63248, N La Salle Blvd
+41.88780, -87.63248, Continue on N La Salle Blvd
41.88919, -87.63254, \0001f
41.89000, -87.63254, \00020
41.89078, -87.63257, \00021
41.90772, -87.63305, \00031
41.90917, -87.63309, \00032
41.91117, -87.63313, \00033
-41.91117, -87.63313, N La Salle Dr
+41.91117, -87.63313, Continue on N La Salle Dr
41.91265, -87.63317, \00035
41.91289, -87.63316, \00036
-41.91289, -87.63316, W Eugenie St
+41.91289, -87.63316, Bear right at W Eugenie St
41.91299, -87.63310, \00038
41.91307, -87.63301, \00039
41.91314, -87.63284, \0003a
-41.91314, -87.63284, N Clark St
+41.91314, -87.63284, Turn left at N Clark St
41.91380, -87.63324, \0003c
41.91485, -87.63388, \0003d
41.91560, -87.63433, \0003e
41.94558, -87.65510, \0006a
41.94654, -87.65592, \0006b
41.94718, -87.65639, \0006c
-41.94718, -87.65639, W Addison St
+41.94718, -87.65639, Turn right at W Addison St
41.94719, -87.65553, \0006e
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
#define MYNAME "TourExchangeFormat"
-#if ! HAVE_LIBEXPAT
-void
-tef_xml_rd_init(const char *fname)
-{
- fatal(MYNAME ": This build excluded TEF support because expat was not installed.\n");
-}
-
-void
-tef_xml_read(void)
-{
-}
-
-#else
-
static char *
trimmed_strdup(const char *str)
{
*/
void
-tef_start(const char *args, const char **attrv)
+tef_start(const char *args, const QXmlStreamAttributes* attrv)
{
- int valid = 0;
- const char **avp = &attrv[0];
+ bool valid = false;
- while (*avp) {
- if (0 == case_ignore_strcmp(avp[0], "Comment")) {
- if (0 == case_ignore_strcmp(avp[1], "TourExchangeFormat")) {
- valid = 1;
+ foreach (QXmlStreamAttribute attr, *attrv) {
+ if (attr.name().compare("Comment", Qt::CaseInsensitive) == 0) {
+ if (attr.value().compare("TourExchangeFormat", Qt::CaseInsensitive) == 0) {
+ valid = true;
}
- } else if (0 == case_ignore_strcmp(avp[0], "Version")) {
- version = atof(avp[1]);
+ } else if (attr.name().compare("Version", Qt::CaseInsensitive) == 0) {
+ version = attr.value().toString().toDouble();
}
- avp+=2;
}
+
if (!valid) {
fatal(MYNAME ": Error in source file.\n");
}
*/
static void
-tef_header(const char *args, const char **attrv)
+tef_header(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
-
route = route_head_alloc();
- while (*avp) {
- if (case_ignore_strcmp(avp[0], "Name") == 0) {
- route->rte_name = trimmed_strdup(avp[1]);
- } else if (case_ignore_strcmp(avp[0], "Software") == 0) {
- route->rte_desc = trimmed_strdup(avp[1]);
+ foreach (QXmlStreamAttribute attr, *attrv) {
+ if (attr.name().compare("Name", Qt::CaseInsensitive) == 0) {
+ route->rte_name = trimmed_strdup(attr.value().toString().toUtf8().constData());
+ } else if (attr.name().compare("Software", Qt::CaseInsensitive) == 0) {
+ route->rte_desc = trimmed_strdup(attr.value().toString().toUtf8().constData());
}
- avp+=2;
}
route_add_head(route);
}
static void
-tef_list_start(const char *args, const char **attrv)
+tef_list_start(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
-
- while (*avp) {
- if (strcmp(avp[0], "ItemCount") == 0) {
- sscanf(avp[1], "%d", &item_count);
- }
- avp+=2;
+ if (attrv->hasAttribute("ItemCount")) {
+ item_count = attrv->value("ItemCount").toString().toUInt();
}
}
}
static void
-tef_item_end(const char *args, const char **unused)
+tef_item_end(const char *args, const QXmlStreamAttributes* unused)
{
waypoint_final();
}
static void
-tef_list_end(const char *args, const char **unused)
+tef_list_end(const char *args, const QXmlStreamAttributes* unused)
{
waypoint_final();
if (waypoints != item_count)
}
static void
-tef_item_start(const char *args, const char **attrv)
+tef_item_start(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
-
waypoints++;
wpt_tmp = waypt_new();
wpt_tmp->wpt_flags.fmt_use ++;
}
- while (*avp) {
- if (0 == case_ignore_strcmp(avp[0], "SegDescription")) {
- wpt_tmp->shortname = trimmed_strdup(avp[1]);
- } else if (0 == case_ignore_strcmp(avp[0], "PointDescription")) {
- wpt_tmp->description = trimmed_strdup(avp[1]);
- } else if ((0 == case_ignore_strcmp(avp[0], "ViaStation")) &&
- (0 == case_ignore_strcmp(avp[1], "true"))) {
- wpt_tmp->wpt_flags.fmt_use = 1; /* only a flag */
- }
+ foreach (QXmlStreamAttribute attr, *attrv) {
+ QString attrstr = attr.value().toString();
+ QByteArray attrtext = attrstr.toUtf8();
+
+ if (attr.name().compare("SegDescription", Qt::CaseInsensitive) == 0) {
+ wpt_tmp->shortname = trimmed_strdup(attrtext.constData());
+ } else if (attr.name().compare("PointDescription", Qt::CaseInsensitive) == 0) {
+ wpt_tmp->description = trimmed_strdup(attrtext.constData());
+ } else if (attr.name().compare("ViaStation", Qt::CaseInsensitive) == 0 &&
+ attr.value().compare("true", Qt::CaseInsensitive) == 0) {
+ wpt_tmp->wpt_flags.fmt_use = 1; /* only a flag */
/* new in TEF V2 */
- else if (0 == case_ignore_strcmp(avp[0], "Instruction")) {
- wpt_tmp->description = trimmed_strdup(avp[1]);
- } else if (0 == case_ignore_strcmp(avp[0], "Altitude")) {
- wpt_tmp->altitude = atof(avp[1]);
- } else if (0 == case_ignore_strcmp(avp[0], "TimeStamp")) {
+ } else if (attr.name().compare("Instruction", Qt::CaseInsensitive) == 0) {
+ wpt_tmp->description = trimmed_strdup(attrtext.constData());
+ } else if (attr.name().compare("Altitude", Qt::CaseInsensitive) == 0) {
+ wpt_tmp->altitude = attrstr.toDouble();
+ } else if (attr.name().compare("TimeStamp", Qt::CaseInsensitive) == 0) {
/* nothing for the moment */
}
+ }
+}
+
+static double
+tef_read_comma_float(const QStringRef& value)
+{
+ QString svalue = value.toString();
+ int cidx;
- avp+=2;
+ cidx = svalue.indexOf(',');
+ if (cidx == -1) {
+ return svalue.toDouble();
}
+
+ QString fixed = svalue.replace(cidx, 1, '.');
+ return fixed.toDouble();
}
static void
-tef_point(const char *args, const char **attrv)
+tef_point(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
- char *comma;
-
if (!wpt_tmp) {
return;
}
- // FIXME: this code should really not be writing into the arg list.
- while (*avp) {
- if (strcmp(avp[0], "y") == 0) {
- char *tbuf = xstrdup(avp[1]);
- comma = strstr(tbuf, ",");
- if (comma) {
- *comma='.';
- }
- sscanf(tbuf, "%lf", &wpt_tmp->latitude);
- xfree(tbuf);
- } else if (strcmp(avp[0], "x") == 0) {
- char *tbuf = xstrdup(avp[1]);
- comma = strstr(tbuf, ",");
- if (comma) {
- *comma='.';
- }
- sscanf(tbuf, "%lf", &wpt_tmp->longitude);
- xfree(tbuf);
- }
- avp+=2;
+ if (attrv->hasAttribute("y")) {
+ wpt_tmp->latitude = tef_read_comma_float(attrv->value("y"));
+ }
+
+ if (attrv->hasAttribute("x")) {
+ wpt_tmp->longitude = tef_read_comma_float(attrv->value("x"));
}
}
xml_read();
}
-#endif
-
static void
tef_xml_rd_deinit(void)
{
#include <ctype.h>
#include <math.h>
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "filterdefs.h"
#include "strptime.h"
strip_html(const utf_string *in)
{
char* outstring, *out;
- // If toUtf8() is used here, we double encode in the OSM test case.
- // this may be a bug here or elsewhere.
- char* incopy, *instr;
- incopy = instr = xstrdup(in->utfstring.toLatin1().data());
+ char* instr = xstrdup(CSTR(in->utfstring));
char tag[8];
unsigned short int taglen = 0;
/*
* We only shorten, so just dupe the input buf for space.
*/
-
- outstring = out = xstrdup(in->utfstring.toUtf8().data());
+ outstring = out = xstrdup(CSTR(in->utfstring));
tag[0] = 0;
while (*instr) {
instr++;
}
*out++ = 0;
- if (incopy) {
- xfree(incopy);
- }
return (outstring);
}
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
+
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
static double ap_lon =0.0;
/* Start of AP block */
-void wfff_s(const char *args, const char **unused)
+void wfff_s(const char *args, const QXmlStreamAttributes* unused)
{
xfreez(ap_mac);
xfreez(ap_ssid);
ap_lon=0.0;
}
-void wfff_mac(const char *args, const char **unused)
+void wfff_mac(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_mac = xstrdup(args);
}
}
-void wfff_ssid(const char *args, const char **unused)
+void wfff_ssid(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_ssid = xstrdup(args);
}
}
-void wfff_type(const char *args, const char **unused)
+void wfff_type(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_type = xstrdup(args);
}
}
-void wfff_mnrssi(const char *args, const char **unused)
+void wfff_mnrssi(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_mnrssi = atof(args);
}
}
-void wfff_mxrssi(const char *args, const char **unused)
+void wfff_mxrssi(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_mxrssi = atof(args);
}
}
-void wfff_chan(const char *args, const char **unused)
+void wfff_chan(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_chan = atoi(args);
}
}
-void wfff_first(const char *args, const char **unused)
+void wfff_first(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_first = xml_parse_time(args);
}
}
-void wfff_last(const char *args, const char **unused)
+void wfff_last(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_last = xstrdup(args);
}
}
-void wfff_wep(const char *args, const char **unused)
+void wfff_wep(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_wep = xstrdup(args);
}
}
-void wfff_hdop(const char *args, const char **unused)
+void wfff_hdop(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_hdop = atof(args);
}
}
-void wfff_lat(const char *args, const char **unused)
+void wfff_lat(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_lat = atof(args);
}
}
-void wfff_lon(const char *args, const char **unused)
+void wfff_lon(const char *args, const QXmlStreamAttributes* unused)
{
if (args) {
ap_lon = atof(args);
/* End of AP Block, set waypoint and add */
static long tosscount=0;
-void wfff_e(const char *args, const char **unused)
+void wfff_e(const char *args, const QXmlStreamAttributes* unused)
{
waypoint* wpt_tmp =0;
char desc[255] ="\0";
*/
+#include <QtCore/QByteArray>
+#include <QtCore/QDebug>
+#include <QtCore/QFile>
+#include <QtCore/QTextCodec>
+#include <QtCore/QXmlStreamAttributes>
+#include <QtCore/QXmlStreamReader>
+
#include "defs.h"
#include "xmlgeneric.h"
#include "cet_util.h"
-#include <QtCore/QDebug>
-#include <QtCore/QXmlStreamReader>
-#include <QtCore/QFile>
#define DEBUG_TAG 0
#if DEBUG_TAG
#include <QtCore/QDebug>
#endif
-#if HAVE_LIBEXPAT
-#include <expat.h>
-static XML_Parser psr;
-#endif
-
static QString current_tag;
-static vmem_t cdatastr;
-static gbfile* ifd;
static xg_tag_mapping* xg_tag_tbl;
-static const char** xg_ignore_taglist;
+static QSet<QString> xg_ignore_taglist;
+
+static const char* rd_fname;
+static QByteArray reader_data;
+static const char* xg_encoding;
+static QTextCodec* utf8_codec = QTextCodec::codecForName("UTF-8");
+static QTextCodec* codec = utf8_codec; // Qt has no vanilla ASCII encoding =(
#define MY_CBUF 4096
if ((global_opts.charset != NULL) && (global_opts.charset != cs)) {
snprintf(buff, sizeof(buff), " encoding=\"%s\"", global_opts.charset_name);
+ QTextCodec* tcodec = QTextCodec::codecForName(global_opts.charset_name);
+ if (tcodec) {
+ codec = tcodec;
+ }
} else {
buff[0] = 0;
}
+
gbfprintf(ofd, "<?xml version=\"1.0\"%s?>\n", buff);
}
write_xml_entity(gbfile* ofd, const QString& indent,
const QString& tag, const QString& value)
{
- char* tmp_ent = xml_entitize(value.toLatin1().data());
- gbfprintf(ofd, "%s<%s>%s</%s>\n", qPrintable(indent), qPrintable(tag), tmp_ent, qPrintable(tag));
+ char* tmp_ent = xml_entitize(CSTRE(value));
+ gbfprintf(ofd, "%s<%s>%s</%s>\n", CSTRE(indent), CSTRE(tag), tmp_ent,
+ CSTRE(tag));
xfree(tmp_ent);
}
write_xml_entity_begin0(gbfile* ofd, const QString& indent,
const QString& tag)
{
- gbfprintf(ofd, "%s<%s>\n", indent.toLatin1().data(), tag.toLatin1().data());
+ gbfprintf(ofd, "%s<%s>\n", CSTRE(indent), CSTRE(tag));
}
void
const QString& tag, const QString& attr,
const QString& attrval)
{
- gbfprintf(ofd, "%s<%s %s=\"%s\">\n", indent.toLatin1().data(), tag.toLatin1().data(), attr.toLatin1().data(), attrval.toLatin1().data());
+ gbfprintf(ofd, "%s<%s %s=\"%s\">\n", CSTRE(indent), CSTRE(tag), CSTRE(attr),
+ CSTRE(attrval));
}
void
const QString& attrval1, const QString& attr2,
const QString& attrval2)
{
- gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", indent.toLatin1().data(), tag.toLatin1().data(), attr1.toLatin1().data(), attrval1.toLatin1().data(), attr2.toLatin1().data(), attrval2.toLatin1().data());
+ gbfprintf(ofd, "%s<%s %s=\"%s\" %s=\"%s\">\n", CSTRE(indent), CSTRE(tag),
+ CSTRE(attr1), CSTRE(attrval1), CSTRE(attr2), CSTRE(attrval2));
}
void
write_xml_entity_end(gbfile* ofd, const QString& indent,
const QString& tag)
{
- gbfprintf(ofd, "%s</%s>\n", indent.toLatin1().data(), tag.toLatin1().data());
+ gbfprintf(ofd, "%s</%s>\n", CSTRE(indent), CSTRE(tag));
}
void
{
gbfprintf(ofd, "<%s>%s</%s>\n",
elname,
- dt.toPrettyString().toUtf8().data(),
+ CSTRE(dt.toPrettyString()),
elname
);
}
return NULL;
}
-/*
- * See if tag element 't' is in our list of things to ignore.
- * Returns 0 if it is not on the list.
- */
-static int
-xml_consider_ignoring(const char* t)
+void
+xml_init(const char* fname, xg_tag_mapping* tbl, const char* encoding)
{
- const char** il;
-
- if (!xg_ignore_taglist) {
- return 0;
- }
-
- for (il = xg_ignore_taglist; *il; il++) {
- if (0 == strcmp(*il, t)) {
- return 1;
+ rd_fname = fname;
+ xg_tag_tbl = tbl;
+ xg_encoding = encoding;
+ if (encoding) {
+ QTextCodec *tcodec = QTextCodec::codecForName(encoding);
+ if (tcodec) {
+ codec = tcodec;
}
}
- return 0;
}
-
-static void
-xml_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr)
+void
+xml_deinit(void)
{
- xg_callback* cb;
- const char* el;
- const char** attrs;
-
- el = xml_convert_to_char_string(xml_el);
- attrs = xml_convert_attrs_to_char_string(xml_attr);
-
- if (xml_consider_ignoring(el)) {
- return;
- }
-
- current_tag.append("/");
- current_tag.append(el);
-
- memset(cdatastr.mem, 0, cdatastr.size);
-
- cb = xml_tbl_lookup(current_tag, cb_start);
- if (cb) {
-#if DEBUG_TAG
- fprintf(stderr, "Start: %s\n", xml_el);
-#endif
- (*cb)(NULL, attrs);
- }
- xml_free_converted_string(el);
- xml_free_converted_attrs(attrs);
+ reader_data.clear();
+ rd_fname = NULL;
+ xg_tag_tbl = NULL;
+ xg_encoding = NULL;
+ codec = utf8_codec;
}
-#if 1
-static void
-xml_cdata(void* dta, const XML_Char* xml_s, int len)
+static bool
+xml_consider_ignoring(const QStringRef& name)
{
- char* estr;
- const char* s = xml_convert_to_char_string_n(xml_s, &len);
-
- vmem_realloc(&cdatastr, 1 + len + strlen(cdatastr.mem));
- estr = (char*) cdatastr.mem + strlen(cdatastr.mem);
- memcpy(estr, s, len);
- estr[len] = 0;
- xml_free_converted_string(s);
+ return xg_ignore_taglist.contains(name.toString());
}
static void
-xml_end(void* data, const XML_Char* xml_el)
+xml_run_parser(QXmlStreamReader& reader, QString& current_tag)
{
- int pos = current_tag.lastIndexOf('/');
- QString s = current_tag.mid(pos + 1);
- const char* el = xml_convert_to_char_string(xml_el);
xg_callback* cb;
+ bool started = false;
- if (xml_consider_ignoring(el)) {
- return;
- }
-
- if (s.compare(el)) {
- fprintf(stderr, "Mismatched tag %s\n", el);
- }
-#if DEBUG_TAG
- qDebug() << current_tag;
-#endif
- cb = xml_tbl_lookup(current_tag, cb_cdata);
- if (cb) {
- (*cb)((char*) cdatastr.mem, NULL);
- }
-
- cb = xml_tbl_lookup(current_tag, cb_end);
- if (cb) {
- (*cb)(el, NULL);
- }
- current_tag.truncate(pos);
- xml_free_converted_string(el);
-}
-
-void xml_read(void)
-{
- int len;
- char buf[MY_CBUF];
-
- while ((len = gbfread(buf, 1, sizeof(buf), ifd))) {
- char* str = buf;
- if (ifd->unicode) {
- str = cet_str_uni_to_utf8((short*)&buf, len >> 1);
- len = strlen(str);
- }
- if (!XML_Parse(psr, str, len, gbfeof(ifd))) {
- fatal(MYNAME ":Parse error at %d: %s\n",
- (int) XML_GetCurrentLineNumber(psr),
- XML_ErrorString(XML_GetErrorCode(psr)));
- }
- if (str != buf) {
- xfree(str);
- }
- }
- XML_ParserFree(psr);
-
-}
-
-void xml_readstring(char* str)
-{
- int len = strlen(str);
- if (!XML_Parse(psr, str, len, 1)) {
- fatal(MYNAME ":Parse error at %d: %s\n",
- (int) XML_GetCurrentLineNumber(psr),
- XML_ErrorString(XML_GetErrorCode(psr)));
- }
- XML_ParserFree(psr);
-}
-
-void xml_readprefixstring(const char* str)
-{
- int len = strlen(str);
- if (!XML_Parse(psr, str, len, 0)) {
- fatal(MYNAME ":Parse error at %d: %s\n",
- (int) XML_GetCurrentLineNumber(psr),
- XML_ErrorString(XML_GetErrorCode(psr)));
- }
-}
-
-void xml_ignore_tags(const char** taglist)
-{
- xg_ignore_taglist = taglist;
-}
-
-void
-xml_init0(const char* fname, xg_tag_mapping* tbl, const char* encoding,
- gbsize_t offset)
-{
- if (fname) {
- ifd = gbfopen(fname, "r", MYNAME);
- if (offset) {
- gbfseek(ifd, offset, SEEK_SET);
- }
- } else {
- ifd = NULL;
- }
+ while (!reader.atEnd()) {
+ switch (reader.tokenType()) {
+ case QXmlStreamReader::StartDocument:
+ if (!reader.documentEncoding().isEmpty()) {
+ codec = QTextCodec::codecForName( CSTR(reader.documentEncoding().toString()) );
+ }
+ if (codec == NULL) {
+ // According to http://www.opentag.com/xfaq_enc.htm#enc_default , we
+ // should assume UTF-8 in absense of other informations. Users can
+ // EASILY override this with xml_init().
+ codec = QTextCodec::codecForName("UTF-8");
+ }
+ started = true;
+ break;
- current_tag.clear();
+ case QXmlStreamReader::StartElement:
+ if (xml_consider_ignoring(reader.name())) {
+ goto readnext;
+ }
- psr = XML_ParserCreate((const XML_Char*)encoding);
- if (!psr) {
- fatal(MYNAME ": Cannot create XML Parser\n");
- }
+ current_tag.append("/");
+ current_tag.append(reader.qualifiedName());
- cdatastr = vmem_alloc(1, 0);
- *((char*)cdatastr.mem) = '\0';
+ cb = xml_tbl_lookup(current_tag, cb_start);
+ if (cb) {
+ const QXmlStreamAttributes attrs = reader.attributes();
+ cb(NULL, &attrs);
+ }
- xg_tag_tbl = tbl;
+ cb = xml_tbl_lookup(current_tag, cb_cdata);
+ if (cb) {
+ QString c = reader.readElementText(QXmlStreamReader::IncludeChildElements);
+ cb(CSTRE(c), NULL);
+ current_tag.chop(reader.qualifiedName().length() + 1);
+ }
+ break;
- cet_convert_init(CET_CHARSET_UTF8, 1);
+ case QXmlStreamReader::EndElement:
+ if (xml_consider_ignoring(reader.name())) {
+ goto readnext;
+ }
- XML_SetUnknownEncodingHandler(psr, cet_lib_expat_UnknownEncodingHandler, NULL);
- XML_SetElementHandler(psr, xml_start, xml_end);
- XML_SetCharacterDataHandler(psr, xml_cdata);
-}
+ cb = xml_tbl_lookup(current_tag, cb_end);
+ if (cb) {
+ cb(CSTRE(reader.name().toString()), NULL);
+ }
+ current_tag.chop(reader.qualifiedName().length() + 1);
+ break;
-/* xml_init0 iwth a default seek argument of zero */
-void
-xml_init(const char* fname, xg_tag_mapping* tbl, const char* encoding)
-{
- xml_init0(fname, tbl, encoding, 0);
-}
+ case QXmlStreamReader::Characters:
+ break;
-void
-xml_init_offset(const char* fname, xg_tag_mapping* tbl, const char* encoding,
- gbsize_t offset)
-{
- xml_init0(fname, tbl, encoding, offset);
-}
+ default:
+ break;
+ };
-void
-xml_deinit(void)
-{
- vmem_free(&cdatastr);
- if (ifd) {
- gbfclose(ifd);
- ifd = NULL;
+readnext:
+ if (started) {
+ reader.readNextStartElement();
+ } else {
+ reader.readNext();
+ }
}
- xg_ignore_taglist = NULL;
-}
-
-#else
-
-static const char* rd_fname;
-static QXmlStreamReader reader;
-
-void
-xml_init(const char* fname, xg_tag_mapping* tbl, const char* encoding)
-{
- rd_fname = fname;
- xg_tag_tbl = tbl;
}
void xml_read(void)
{
QFile file(rd_fname);
+ QString current_tag;
+
file.open(QIODevice::ReadOnly);
- reader.setDevice(&file);
- QString current_tag;
- while (!reader.atEnd()) {
- switch (reader.tokenType()) {
- case QXmlStreamReader::StartElement: {
- current_tag.append("/");
- current_tag.append(reader.name());
- xg_callback* cb = xml_tbl_lookup(current_tag, cb_start);
- if (cb) {
- const char** attrs;
- (*cb)(NULL, attrs);
- }
- cb = xml_tbl_lookup(current_tag, cb_cdata);
- if (cb) {
- QString c = reader.readElementText();
- (*cb)(c.toUtf8().data(), NULL);
- current_tag.chop(reader.name().length() + 1);
- }
- }
- break;
- case QXmlStreamReader::Characters:
- break;
- case QXmlStreamReader::EndElement: {
- xg_callback* cb = xml_tbl_lookup(current_tag, cb_end);
- if (cb) {
- (*cb)(NULL, NULL);
- }
- current_tag.chop(reader.name().length() + 1);
- }
- break;
- default:
- break;
- };
- reader.readNextStartElement();
- }
+ QXmlStreamReader reader(&file);
+ xml_run_parser(reader, current_tag);
}
void xml_ignore_tags(const char** taglist)
{
- xg_ignore_taglist = taglist;
+ for (; taglist && *taglist; taglist++) {
+ xg_ignore_taglist.insert(QString::fromUtf8(*taglist));
+ }
}
void xml_readprefixstring(const char* str)
{
+ reader_data.append(str);
}
-void xml_readstring(char* str)
+void xml_readstring(const char* str)
{
-}
+ QString current_tag;
-void
-xml_deinit(void)
-{
+ reader_data.append(str);
+
+ QXmlStreamReader reader(reader_data);
+
+ xml_run_parser(reader, current_tag);
}
-#endif
/******************************************/
cb_end,
} xg_cb_type;
-typedef void (xg_callback)(const char*, const char**);
+typedef void (xg_callback)(const char*, const QXmlStreamAttributes*);
typedef struct xg_tag_mapping {
xg_callback* tag_cb;
void xml_init_offset(const char* fname, xg_tag_mapping* tbl,
const char* encoding, gbsize_t offset);
void xml_read(void);
-void xml_readstring(char* str);
+void xml_readstring(const char* str);
void xml_readprefixstring(const char* str);
void xml_deinit(void);
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
#include "jeeps/gpsmath.h"
#define MYNAME "xol"
-#if ! HAVE_LIBEXPAT
-void
-xol_rd_init(const char *fname)
-{
- fatal(MYNAME ": This build excluded \"" MYNAME "\" support because expat was not installed.\n");
-}
-
-void
-xol_read(void)
-{
-}
-
-#else
-
static xg_callback xol_shape, xol_shape_end;
static xg_callback xol_waypt, xol_overlay;
static void
-xol_overlay(const char *args, const char **attrv)
+xol_overlay(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
-
- while (*avp) {
- if (strcmp(avp[0], "version") == 0) {
- if (strcmp(avp[1], "1.0") != 0) {
- fatal(MYNAME ": Unsupported version %s.\n", avp[1]);
- }
+ if (attrv->hasAttribute("version")) {
+ if (attrv->value("version") != "1.0") {
+ fatal(MYNAME ": Unsupported version %s.\n",
+ attrv->value("version").toString().toUtf8().constData());
}
-
- avp+=2;
}
}
static void
-xol_shape(const char *args, const char **attrv)
+xol_shape(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
-
- while (*avp) {
- if (strcmp(avp[0], "type") == 0) {
- if (strcmp(avp[1], "waypoint") == 0) {
- wpt = waypt_new();
- } else if (strcmp(avp[1], "polyline") == 0) {
- trk = route_head_alloc();
- track_add_head(trk);
- }
- } else if (strcmp(avp[0], "name") == 0) {
- if (wpt) {
- wpt->shortname = xstrdup(avp[1]);
- } else if (trk) {
- trk->rte_name = xstrdup(avp[1]);
- }
- } else if (strcmp(avp[0], "comment") == 0) {
- if (wpt) {
- wpt->notes = xstrdup(avp[1]);
- }
- } else if (strcmp(avp[0], "alt") == 0) {
- if (wpt) {
- wpt->altitude = atof(avp[1]);
- }
- } else if (strcmp(avp[0], "timestamp") == 0) {
- if (wpt) {
- wpt->creation_time = xml_parse_time(avp[1]);
- }
- } else if (strcmp(avp[0], "icon") == 0) {
- if (wpt) {
- wpt->icon_descr = avp[1];
- }
+ if (attrv->hasAttribute("type")) {
+ if (attrv->value("type") == "waypoint") {
+ wpt = waypt_new();
+ } else if (attrv->value("type") == "polyline") {
+ trk = route_head_alloc();
+ track_add_head(trk);
+ }
+ }
+
+ if (attrv->hasAttribute("name")) {
+ if (wpt) {
+ wpt->shortname = xstrdup(attrv->value("name").toString().toUtf8().constData());
+ } else if (trk) {
+ trk->rte_name = xstrdup(attrv->value("name").toString().toUtf8().constData());
+ }
+ }
+
+ if (wpt) {
+ if (attrv->hasAttribute("comment")) {
+ wpt->notes = xstrdup(attrv->value("comment").toString().toUtf8().constData());
+ }
+
+ if (attrv->hasAttribute("alt")) {
+ wpt->altitude = attrv->value("alt").toString().toDouble();
}
- avp+=2;
+ if (attrv->hasAttribute("timestamp")) {
+ wpt->creation_time = xml_parse_time(attrv->value("timestamp").toString().toUtf8().constData());
+ }
+
+ if (attrv->hasAttribute("icon")) {
+ wpt->icon_descr = xstrdup(attrv->value("icon").toString().toUtf8().constData());
+ }
}
}
static void
-xol_shape_end(const char *args, const char **unused)
+xol_shape_end(const char *args, const QXmlStreamAttributes* unused)
{
if (wpt) {
if (trk) {
}
static void
-xol_waypt(const char *args, const char **attrv)
+xol_waypt(const char *args, const QXmlStreamAttributes* attrv)
{
- const char **avp = &attrv[0];
int x=0, y=0;
- while (*avp) {
- if (strcmp(avp[0], "y") == 0) {
- y = atoi(avp[1]);
- } else if (strcmp(avp[0], "x") == 0) {
- x = atoi(avp[1]);
- }
- avp+=2;
+ if (attrv->hasAttribute("y")) {
+ y = attrv->value("y").toString().toInt();
+ }
+
+ if (attrv->hasAttribute("x")) {
+ x = attrv->value("x").toString().toInt();
}
GPS_Math_Swiss_EN_To_WGS84((double)x, (double)y, &wpt->latitude, &wpt->longitude);
xml_read();
}
-#endif
-
static void
xol_rd_deinit(void)
{
*/
+#include <QtCore/QXmlStreamAttributes>
+
#include "defs.h"
#include "xmlgeneric.h"
fatal("Writing file of type %s is not supported\n", MYNAME);
}
-void wpt_s(const char *args, const char **unused)
+void wpt_s(const char *args, const QXmlStreamAttributes* unused)
{
wpt_tmp = waypt_new();
}
-void wpt_e(const char *args, const char **unused)
+void wpt_e(const char *args, const QXmlStreamAttributes* unused)
{
waypt_add(wpt_tmp);
wpt_tmp = NULL;
}
-void wpt_lat(const char *args, const char **unused)
+void wpt_lat(const char *args, const QXmlStreamAttributes* unused)
{
wpt_tmp->latitude = atof(args);
}
-void wpt_lon(const char *args, const char **unused)
+void wpt_lon(const char *args, const QXmlStreamAttributes* unused)
{
wpt_tmp->longitude = atof(args);
}
-void wpt_addr(const char *args, const char **unused)
+void wpt_addr(const char *args, const QXmlStreamAttributes* unused)
{
if (wpt_tmp->notes) {
wpt_tmp->notes = xstrappend(wpt_tmp->notes, as);